/* Y o u r   D e s c r i p t i o n                       */
/*                            AppBuilder Photon Code Lib */
/*                                         Version 1.13X */

/* Standard headers */
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>

/* Toolkit headers */
#include <Ph.h>
#include <Pt.h>
#include <Ap.h>

/* Local headers */
#include "ph_rline.h"
#include "abimport.h"
#include "proto.h"

extern lsrRunLine runLine;

int resizeWin( PtWidget_t *widget, ApInfo_t *apinfo, PtCallbackInfo_t *cbinfo )
{
	PtArg_t arg;
	PhRect_t rect;

	/* eliminate 'unreferenced' warnings */
	widget = widget, apinfo = apinfo, cbinfo = cbinfo;

	/* get the interior extent of the eye wind widget */
	PtBasicWidgetCanvas((PtWidget_t *)ABW_runLineWindow, &runLine.canvas);
	runLine.area.pos.x = runLine.canvas.ul.x;
	runLine.area.pos.y = runLine.canvas.ul.y;
	runLine.area.size.w = runLine.canvas.lr.x - runLine.canvas.ul.x;
	runLine.area.size.h = runLine.canvas.lr.y - runLine.canvas.ul.y;

	return( Pt_CONTINUE );
}

int manageWin( PtWidget_t *widget, ApInfo_t *apinfo, PtCallbackInfo_t *cbinfo )
{
	PhWindowEvent_t *winEvent;
	PtArg_t args[2];
	static int iconified;

	/* eliminate 'unreferenced' warnings */
	widget = widget, apinfo = apinfo, cbinfo = cbinfo;

	/* get pointer to the window event structure */
	winEvent = (PhWindowEvent_t *)cbinfo->cbdata;

	/* check to see which type event evoked this callback */
	if((winEvent->event_f == Ph_WM_FOCUS) ||
	   (winEvent->event_f == Ph_WM_TOFRONT)) {
		/* damage all widgets to force redraws */
		PtDamageWidget(ABW_runLineMenuBar);
		PtDamageWidget(ABW_runLineOptions);
		PtDamageWidget(ABW_dispResetButton);
		PtDamageWidget(ABW_cntrlBtnPane);
		PtDamageWidget(ABW_chan0Toggle);
		PtDamageWidget(ABW_chan1Toggle);
		PtDamageWidget(ABW_chan2Toggle);
		PtDamageWidget(ABW_chan3Toggle);
		PtDamageWidget(ABW_chan4Toggle);
		PtDamageWidget(ABW_chan5Toggle);
		PtDamageWidget(ABW_chan6Toggle);
		PtDamageWidget(ABW_chan7Toggle);
		PtDamageWidget(ABW_rlineToggle);
		PtDamageWidget(ABW_unitsToggle);
		PtDamageWidget(ABW_triggerLabel);
		PtDamageWidget(ABW_rlTrigButton);
		PtDamageWidget(ABW_displayLabel);
		PtDamageWidget(ABW_rlRepeatButton);
		PtDamageWidget(ABW_levelLabel);
		PtDamageWidget(ABW_rlTrigLevel);
	}

	if(winEvent->event_f == Ph_WM_CLOSE) {
		/* shut off running line processing by msec_clock */
		i_b->d_flags &= ~D_RLINE;
		release_(&myptp->p_sem);
		myptp->p_state |= P_EXIT_ST;
		myptp->p_id = 0;
		exit(EXIT_SUCCESS);
	}
	else if(winEvent->event_f == Ph_WM_ICON && !iconified) {
		iconified = 1;

		/* shut off raster processing */
		PtSetArg(&args[0], Pt_ARG_TIMER_INITIAL, 0, 0);
		PtSetArg(&args[1], Pt_ARG_TIMER_REPEAT, 0, 0);
		PtSetResources(ABW_rlTimer, 2, args);
	}
	else if(winEvent->event_f == Ph_WM_ICON && !iconified) {
		iconified = 0;

		/* turn on raster processing  */
		PtSetArg(&args[0], Pt_ARG_TIMER_INITIAL, 16, 0);
		PtSetArg(&args[1], Pt_ARG_TIMER_REPEAT, 16, 0);
		PtSetResources(ABW_rlTimer, 2, args);
	}

	return( Pt_CONTINUE );
}
